<?php
/* SVN FILE: $Id: cp_skin_plugin_bank.php 248 2009-11-12 16:29:29Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Bank plugin ACP html
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 248 $
* @lastrevision $Date: 2009-11-12 16:29:29 +0000 (Thu, 12 Nov 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-11-12 16:29:29 +0000 (Thu, 12 Nov 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/plugins/bank/skin_cp/cp_skin_plugin_bank.php $
*/

class cp_skin_plugin_bank extends output
{

/**
 * Prevent our main destructor being called by this class
 *
 * @access	public
 * @return	void
 */
public function __destruct()
{
}

/**
 * Manage all the bank starters
 *
 * @access	public
 * @return	string	HTML
 */
public function manageStarters() {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['manage_bank_starters']}</h2>
</div>
<div id='manageBankStaters'>
	<div class='acp-box'>
		<h3>{$this->lang->words['account_starter_list']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['starter_name']}</th>
				<th>{$this->lang->words['starter_description']}</th>
				<th>{$this->lang->words['starter_interest']}</th>
				<th>{$this->lang->words['starter_interest_time']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
if(is_array($this->caches['ibm_bank_starter']) and count($this->caches['ibm_bank_starter']))
{
	foreach($this->caches['ibm_bank_starter'] as $starter)
	{
		$description = IPSText::getTextClass('bbcode')->preDisplayParse($starter['s_description']);
		$hours = round($starter['s_interest_time']/3600,3);
		$hours = $hours == 1 ? $this->lang->words['1_hour'] : sprintf($this->lang->words['x_hours'], $hours);
		$IPBHTML .= <<<EOF
			<tr>
				<td>{$starter['s_name']}</td>
				<td>{$description}</td>
				<td>{$starter['s_interest_rate']}%</td>
				<td>{$hours}</td>
				<td>
					<img class='ipbmenu' id="menum-{$starter['starter_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$starter['starter_id']}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=starter&amp;do=edit&amp;starter={$starter['starter_id']}'>{$this->lang->words['edit_bank_starter']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=starter&amp;do=delete&amp;starter={$starter['starter_id']}'>{$this->lang->words['delete_bank_starter']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
	}
}
else
{
	$IPBHTML .= <<<EOF
			<tr>
				<td colspan='5' style='text-align: center'><strong>{$this->lang->words['no_starters_added']}</strong></td>
			</tr>

EOF;
}

$IPBHTML .= <<<EOF
		</table>
	</div>
</div>

EOF;

return $IPBHTML;
}

/**
 * Adding/editing bank starter form
 *
 * @access	public
 * @return	string	HTML
 */
public function starterForm( array $starter, $nextDo, $title, $submitValue ) {

if ( IPSText::getTextClass('editor')->method == 'rte' )
{
	$_description = IPSText::getTextClass('bbcode')->convertForRTE( $starter['s_description'] );
}
else
{
	$_description = IPSText::getTextClass('bbcode')->preEditParse( $starter['s_description'] );
}

$form['s_name'] = ipsRegistry::getClass('output')->formInput('s_name', $starter['s_name']);
$form['s_description'] = IPSText::getTextClass('editor')->showEditor( $_description, 's_description' );
$form['s_interest_rate'] = ipsRegistry::getClass('output')->formSimpleInput('s_interest_rate', $starter['s_interest_rate']);
$form['s_interest_time'] = sprintf($this->lang->words['x_hours'], ipsRegistry::getClass('output')->formSimpleInput('s_interest_time', $starter['s_interest_time']/3600));
$form['s_deposit_fee'] = ipsRegistry::getClass('output')->formSimpleInput('s_deposit_fee', $starter['s_deposit_fee']);
$form['s_withdraw_fee'] = ipsRegistry::getClass('output')->formSimpleInput('s_withdraw_fee', $starter['s_withdraw_fee']);
$form['create_price'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('create_price', $starter['create_price'], 10));
$form['delete_fee'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('delete_fee', $starter['delete_fee'], 10));

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$title}</h2>
</div>

<div id='bankStarterFormPage'>
	<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=starter&amp;do={$nextDo}&amp;starter={$this->request['starter']}' id='bankStarterForm'>
		<input type='hidden' name='_admin_auth_key' value='{$this->registry->adminFunctions->getSecurityKey()}' />
		<div class='acp-box'>
			<h3>{$title}</h3>
			<ul class='acp-form alternate_rows'>
				<li>
					<label>
						{$this->lang->words['form_starter_name']}
						<span class="desctext">{$this->lang->words['form_starter_name_desc']}</span>
					</label>
					{$form['s_name']}
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_desc']}
						<span class="desctext">{$this->lang->words['form_starter_desc_desc']}</span>
					</label>
					<br />
					<div style="display:inline-block; width:100%">
						{$form['s_description']}
					</div>
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_interest']}
						<span class="desctext">{$this->lang->words['form_starter_interest_desc']}</span>
					</label>
					{$form['s_interest_rate']}%
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_itime']}
						<span class="desctext">{$this->lang->words['form_starter_itime_desc']}</span>
					</label>
					{$form['s_interest_time']}
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_deposit']}
						<span class="desctext">{$this->lang->words['form_starter_deposit_desc']}</span>
					</label>
					{$form['s_deposit_fee']}%
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_withdraw']}
						<span class="desctext">{$this->lang->words['form_starter_withdraw_desc']}</span>
					</label>
					{$form['s_withdraw_fee']}%
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_create']}
						<span class="desctext">{$this->lang->words['form_starter_create_desc']}</span>
					</label>
					{$form['create_price']}
				</li>
				<li>
					<label>
						{$this->lang->words['form_starter_delete']}
						<span class="desctext">{$this->lang->words['form_starter_delete_desc']}</span>
					</label>
					{$form['delete_fee']}
				</li>
			</ul>
			<div class='acp-actionbar'>
				<div class='centeraction'>
					<input type='submit' value='{$submitValue}' class='button primary'>
				</div>
			</div>
		</div>
	</form>
</div>
EOF;

return $IPBHTML;
}

/**
 * Search for a member
 *
 * @access	public
 * @return	string	HTML
 */
public function searchMemberForAccount() {

$form['member'] = ipsRegistry::getClass('output')->formInput('member_name');
$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['bank_account_by_name']}</h2>
</div>

<div id='bankMemberPage'>
	<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=accounts&amp;do=accounts' id='bankMemberForm'>
		<input type='hidden' name='_admin_auth_key' value='{$this->registry->adminFunctions->getSecurityKey()}' />
		<div class='acp-box'>
			<h3>{$this->lang->words['bank_account_by_name']}</h3>
			<ul class='acp-form alternate_rows'>
				<li>
					<label>{$this->lang->words['member_name']}</label>
					{$form['member']}
				</li>
			</ul>
			<div class='acp-actionbar'>
				<div class='centeraction'>
					<input type='submit' value='{$this->lang->words['search_button']}' class='button primary'>
				</div>
			</div>
		</div>
	</form>
</div>
<script type='text/javascript' language='javascript'>
document.observe("dom:loaded", function(){
	var bankAccountMember = new ipb.Autocomplete( $('member_name'), { multibox: false, url: acp.autocompleteUrl, templates: { wrap: acp.autocompleteWrap, item: acp.autocompleteItem } } );
});

</script>

EOF;

return $IPBHTML;
}

/**
 * Lists all the bank accounts belonging to a member
 *
 * @access	public
 * @return	string	HTML
 */
public function listMemberBankAccount(array $member, array $accounts) {

$this->lang->words['accounts_by_x'] = sprintf($this->lang->words['accounts_by_x'],$member['members_display_name']);
$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['accounts_by_x']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=accounts&amp;do=add&amp;member_id={$member['member_id']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='' />
				{$this->lang->words['add_bank_account']}
			</a>
		</li>
	</ul>
</div>
<div id='manageBankStaters'>
	<div class='acp-box'>
		<h3>{$this->lang->words['accounts_by_x']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['account_id']}</th>
				<th>{$this->lang->words['balance']}</th>
				<th>{$this->lang->words['interest']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
if(count($accounts))
{
	foreach($accounts as $account)
	{
		$id = bankPluginFunctions::getBankAccountID($account);
		$balance = marketFormatter::formatCurrency($account['balance']);
		$interest = str_replace(array("<#RATE#>","<#TIME#>","<#LAST#>"),array($account['interest_rate']."%",marketFormatter::relativeTimeFull($account['a_interest_time'],'LONG'),$this->registry->getClass('class_localization')->formatTime($account['a_last_interest'],'long')),$this->lang->words['full_interest']);
		$IPBHTML .= <<<EOF
			<tr>
				<td>{$id}</td>
				<td>{$balance}</td>
				<td>{$interest}</td>
				<td>
					<img class='ipbmenu' id="menum-{$account['starter_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$account['starter_id']}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=accounts&amp;do=edit&amp;account_id={$account['account_id']}'>{$this->lang->words['edit_bank_account']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=accounts&amp;do=delete&amp;account_id={$account['account_id']}'>{$this->lang->words['delete_bank_account']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
	}
}
else
{
	$IPBHTML .= <<<EOF
			<tr>
				<td colspan='5' style='text-align: center'><strong>{$this->lang->words['member_no_bank_accounts']}</strong></td>
			</tr>

EOF;
}

$IPBHTML .= <<<EOF
		</table>
	</div>
</div>

EOF;

return $IPBHTML;
}

/**
 * Adding/editing bank account form
 *
 * @access	public
 * @return	string	HTML
 */
public function accountForm( array $account, $nextDo, $title, $submitValue ) {

if($account['a_mem_id'])
{
	$member = $this->DB->buildAndFetch(array('select'=>'*','from'=>'members','where'=>"member_id=".$account['a_mem_id']));
}

$this->lang->words['adjust_last_time_desc'] = sprintf($this->lang->words['adjust_last_time_desc'],$this->registry->getClass('class_localization')->formatTime($account['a_last_interest'],'long'));

$form['a_name'] = ipsRegistry::getClass('output')->formInput('a_name', $account['a_name']);
$form['member_name'] = ipsRegistry::getClass('output')->formInput('member_name',$member['members_display_name']);
$form['balance'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('balance', $account['balance'], 10));
$form['a_interest_time'] = sprintf($this->lang->words['x_hours'], ipsRegistry::getClass('output')->formSimpleInput('a_interest_time', $account['a_interest_time']/3600));
$form['interest_rate'] = ipsRegistry::getClass('output')->formSimpleInput('interest_rate', $account['interest_rate']);
$form['adjust_last_time'] = sprintf($this->lang->words['x_minutes'],ipsRegistry::getClass('output')->formSimpleInput('adjust_last_time', 0));
$form['a_deposit_fee'] = ipsRegistry::getClass('output')->formSimpleInput('a_deposit_fee', $account['a_deposit_fee']);
$form['a_withdraw_fee'] = ipsRegistry::getClass('output')->formSimpleInput('a_withdraw_fee', $account['a_withdraw_fee']);
$form['a_delete_fee'] = marketFormatter::currencyFormat(ipsRegistry::getClass('output')->formSimpleInput('a_delete_fee', $account['a_delete_fee'], 10));

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$title}</h2>
</div>

<div id='bankAccountFormPage'>
	<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=accounts&amp;do={$nextDo}' id='bankAccountForm'>
		<input type='hidden' name='_admin_auth_key' value='{$this->registry->adminFunctions->getSecurityKey()}' />
		<input type='hidden' name='account_id' value='{$account['account_id']}' />
		<div class='acp-box'>
			<h3>{$title}</h3>
			<ul class='acp-form alternate_rows'>
				<li>
					<label>
						{$this->lang->words['account_name']}
						<span class="desctext">{$this->lang->words['account_name_desc']}</span>
					</label>
					{$form['a_name']}
				</li>
				<li>
					<label>
						{$this->lang->words['owner_name']}
						<span class="desctext">{$this->lang->words['owner_name_desc']}</span>
					</label>
					{$form['member_name']}
				</li>
				<li>
					<label>
						{$this->lang->words['balance']}
						<span class="desctext">{$this->lang->words['balance_desc']}</span>
					</label>
					{$form['balance']}
				</li>
				<li>
					<label>
						{$this->lang->words['interest_time']}
						<span class="desctext">{$this->lang->words['interest_time_desc']}</span>
					</label>
					{$form['a_interest_time']}
				</li>
				<li>
					<label>
						{$this->lang->words['interest_rate']}
						<span class="desctext">{$this->lang->words['interest_rate_desc']}</span>
					</label>
					{$form['interest_rate']}%
				</li>
				<li>
					<label>
						{$this->lang->words['adjust_last_time']}
						<span class="desctext">{$this->lang->words['adjust_last_time_desc']}</span>
					</label>
					{$form['adjust_last_time']}
					<input type='hidden' name='a_last_interest' value='{$account['a_last_interest']}'>
				</li>
				<li>
					<label>
						{$this->lang->words['deposit_fee']}
						<span class="desctext">{$this->lang->words['deposit_fee_desc']}</span>
					</label>
					{$form['a_deposit_fee']}%
				</li>
				<li>
					<label>
						{$this->lang->words['withdraw_fee']}
						<span class="desctext">{$this->lang->words['withdraw_fee_desc']}</span>
					</label>
					{$form['a_withdraw_fee']}%
				</li>
				<li>
					<label>
						{$this->lang->words['remove_fee']}
						<span class="desctext">{$this->lang->words['remove_fee_desc']}</span>
					</label>
					{$form['a_delete_fee']}
				</li>
			</ul>
			<div class='acp-actionbar'>
				<div class='centeraction'>
					<input type='submit' value='{$submitValue}' class='button primary'>
				</div>
			</div>
		</div>
	</form>
</div>
<script type='text/javascript' language='javascript'>
document.observe("dom:loaded", function(){
	var bankAccountMember = new ipb.Autocomplete( $('member_name'), { multibox: false, url: acp.autocompleteUrl, templates: { wrap: acp.autocompleteWrap, item: acp.autocompleteItem } } );
});

</script>

EOF;

return $IPBHTML;
}

/**
 * Listing all the transactions done
 *
 * @access	public
 * @return	string	HTML
 */
public function transactionLogs( array $logs, $links ) {

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['transaction_logs_title']}</h2>
</div>

<div id='catgories'>
	<div class='acp-box'>
		<h3>{$this->lang->words['transaction_logs_table']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['transaction_account_id']}</th>
				<th>{$this->lang->words['transaction_ip_address']}</th>
				<th>{$this->lang->words['transaction_time']}</th>
				<th>{$this->lang->words['transaction_action']}</th>
			</tr>

EOF;
foreach($logs as $log)
{
	$time = $this->registry->getClass('class_localization')->getDate( $log['l_timestamp'], 'LONG' );
	$action = $this->lang->words['acp_transaction_'.$log['l_action']];
	$IPBHTML .= <<<EOF
			<tr>
				<td style='white-space:nowrap'>{$log['l_account_id']}</td>
				<td style='white-space:nowrap'>{$log['l_ip_address']}</td>
				<td style='white-space:nowrap'>{$time}</td>
				<td style='white-space:nowrap'>{$action}</td>
			</tr>

EOF;
}
if(count($logs) == 0)
{
	$IPBHTML .= <<<EOF
			<tr>
				<td style='white-space:nowrap; text-align:center' colspan='6'><strong>{$this->lang->words['no_transactions']}</strong></td>
			</tr>

EOF;
}
$IPBHTML .= <<<EOF
		</table>
		<div class='acp-actionbar'>
			<div class="leftaction">{$links}</div>
		</div>
	</div>
</div>

EOF;

return $IPBHTML;
}

}